package AI.screens
{
	import com.cheezeworld.AI.Behaviors.*;
	import com.cheezeworld.entity.*;
	import com.cheezeworld.math.Geometry;
	import com.cheezeworld.screens.IScreenItem;
	import com.cheezeworld.screens.Root;
	import com.cheezeworld.utils.Input;
	
	import flash.display.Graphics;

	public class FollowPathDemo extends AIDemoScreen
	{
		public function FollowPathDemo(a_parentScreen:IScreenItem=null)
		{
			super(a_parentScreen);
			
			screenLabel = "Follow Path";
			
			// Create a Path
			m_path=[];
			createPath();
			
			// Create some boids
			var boid1:Boid;
			boid1 = _factory.getEntity( "Boid1", _gameworld ) as Boid;
			boid1.scale = 1;			
			boid1.newPos.Set( 250, 250 );
			boid1.steering.addBehavior( new FollowPath( m_path, true, 30*30 )); 
		}
		
		public override function update(a_timePassed:int):void
		{
			super.update(a_timePassed);
			
			if( Input.instance.isMousePressed )
			{
				createPath();
			}
		}
		
		private function createPath() : void
		{
			var i:int = 0;
						
			var temp:Array = Geometry.getRandomPolygon( 6, 50, 50, Root.WIDTH, Root.HEIGHT );
			m_path[0] = temp[i];
			
			var g:Graphics = graphics;
			g.clear();
			g.lineStyle( 1, 0x22FF22 );
			g.moveTo( m_path[0].x, m_path[0].y );
			for(i=0; i<7; i++ )
			{
				i < 6 ? m_path[i] = temp[i] : i;
				i < 6 ? g.lineTo( m_path[i].x, m_path[i].y ) : g.lineTo( m_path[0].x, m_path[0].y );
			}
			
		}
		
		
		private var m_path:Array;
		
	}
}